<template>
  <mu-dialog title="提示" width="480" :open.sync="decision.openDecisionDialog">
    <label>发生冲突！发现您本地已经存在书签，请做出您的决定：</label>
    <mu-select v-model="decision.value" full-width>
      <mu-option v-for="option in decision.options" :key="option" :label="option" :value="option"></mu-option>
    </mu-select>
    <mu-button slot="actions" flat color="primary" @click="closeDecisionDialog">ok</mu-button>
  </mu-dialog>
</template>

<script>
import plugin_api from "../plugin/plugin-api";

export default {
  name: "DecisionMaker",

  data(){
    return {
      decision:{
        openDecisionDialog: false,
        options: Object.keys(plugin_api.Decisions).map(key => plugin_api.Decisions[key]),
        value: '',
        stateMyDecision: undefined
      },
    }
  },

  methods: {
    async makeDecision(){
      const self = this;
      return new Promise((resolve)=>{
        self.decision.openDecisionDialog = true;
        self.decision.stateMyDecision = resolve;
      });
    },

    closeDecisionDialog(){
      const self = this;
      if(typeof self.decision.stateMyDecision === 'function'){
        self.decision.openDecisionDialog = false;
        self.decision.stateMyDecision(self.decision.value);
      }
    }
  }
}
</script>

<style scoped>

</style>